package com.adgcsumb.spookynumberguess;

import android.os.Bundle;
import java.util.Random;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	
	private Button highbtn;
	private Button lowbtn;
	private Button yesbtn;
	private Button restartbtn;
	private TextView text;
	Random randomGenerator;
	int choice;
	int gnumber; 
	int minnum = 1; 
	int maxnum = 10;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	
    	//so this is how you troll
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        highbtn = (Button) findViewById(R.id.highbtn);
        lowbtn=(Button) findViewById(R.id.lowbtn);
        restartbtn = (Button) findViewById(R.id.restartbtn);
        yesbtn=(Button) findViewById(R.id.yesbtn);
        text=(TextView) findViewById(R.id.text);
        
        text.setText("Choose a Spooky Number");
        text.setTextSize(40);
        
        text.setVisibility(View.VISIBLE);
        yesbtn.setVisibility(View.INVISIBLE);
        lowbtn.setVisibility(View.INVISIBLE);
        highbtn.setVisibility(View.INVISIBLE);
        restartbtn.setVisibility(View.INVISIBLE);
        text.setClickable(true);
        
        randomGenerator = new Random();
       
        
    }
    
    public void start(View v)
    {
        restartbtn.setVisibility(View.INVISIBLE);
    	text.setClickable(false);
        yesbtn.setVisibility(View.VISIBLE);
        lowbtn.setVisibility(View.VISIBLE);
        highbtn.setVisibility(View.VISIBLE);
        choice = randomGenerator.nextInt(maxnum) + 1; 
        
        text.setText("Is your number \n  " + choice + " ?");
    
    }
    
    public void higher(View v)
    {
    	
    	text.setClickable(false);
    	gnumber ++;
    	if(choice == 10)
    	{
    		text.setText(maxnum + "is the maximum number!");
    		
    	}
    	else
    	{
	    	if(choice > minnum)
	    		minnum = choice; 
	    	choice = randomGenerator.nextInt(maxnum - (minnum - 1)) + minnum;
	    	
	    	text.setText("Is your number \n  " + choice + " ?");
	    	if (maxnum == minnum) {
	    		text.setTextSize(18);
    			text.setText("I know your number! Be very afraid \n" + "Number of guesses " + gnumber); 
    			restartbtn.setVisibility(View.VISIBLE);
    			lowbtn.setVisibility(View.INVISIBLE);
    			highbtn.setVisibility(View.INVISIBLE);
    			yesbtn.setVisibility(View.INVISIBLE);
	    	} 
    	}
    }
    public void lower(View v)
    {
    	text.setClickable(false);
    	gnumber ++;
    	if(choice == 1)
    	{
    		text.setText("1 is the minimum number!");
    	}
    	else
    	{
    		if (choice < maxnum) 
    			maxnum = choice; 
    		choice = randomGenerator.nextInt(maxnum - (minnum - 1)) + minnum ;
	    	text.setText("Is your number \n  " + choice + " ?"); 
	    	if (maxnum == minnum) {
	    		text.setTextSize(18);
    			text.setText("I know your number! Be very afraid \n" + "Number of guesses " + gnumber); 
    			restartbtn.setVisibility(View.VISIBLE);
    			lowbtn.setVisibility(View.INVISIBLE);
    			highbtn.setVisibility(View.INVISIBLE);
    			yesbtn.setVisibility(View.INVISIBLE);
	    	} 
    	}
    	
    }
    public void correct(View v)
    {
    	if(yesbtn.isPressed()== true)
    	{
    		text.setTextSize(18);
    		text.setText("I know your number! Be very afraid \n" + "Number of guesses " + gnumber); 
    		restartbtn.setVisibility(View.VISIBLE);
    		lowbtn.setVisibility(View.INVISIBLE);
    	    highbtn.setVisibility(View.INVISIBLE);
    	    yesbtn.setVisibility(View.INVISIBLE);
    	}
    }
    public void restart(View v)
    {
    	text.setTextSize(20);	
    	text.setClickable(false);
    	gnumber = 0;
    	minnum = 1; 
    	maxnum = 10; 
    	start(v);
    }
    


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
